package cn.xyy.common.domain.system.auth;

import cn.xyy.common.annotation.jdbc.Columns;
import cn.xyy.common.annotation.jdbc.Tables;

import java.util.List;

/**
 * 部门
 * 
 * @author xyy
 *
 */
@Tables("t_sys_dept")
public class Department implements Comparable<Department> {

	// Fields
	@Columns(value = "dept_id", primaryKey = true)
	private String id;
	@Columns("name")
	private String name;
	@Columns("parent_id")
	private String parentId;
	@Columns("sorts")
	private Integer sorts;
	@Columns("levels")
	private Integer levels;// 等级0 集团，1分公司 2部门
	@Columns("for_service")
	private Integer forService;//
	@Columns("status")
	private Integer status; // 1启用，2停用

	private String parentName;

	// 子
	private List<Department> children;
	private Integer nodeDeptId;//
	private String nodeDeptName;// 如果部门是集团直属部门，nodeDeptName为集团；如果为分公司下属部门，nodeDeptName为分公司

	public boolean isRoot() {
		if (this.parentId.equals("0")) {
			return true;
		}
		return false;
	}

	public String getId() {
		return id;
	}

	public Department setId(String id) {
		this.id = id;
		return this;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public Integer getSorts() {
		return sorts;
	}

	public void setSorts(Integer sorts) {
		this.sorts = sorts;
	}

	public Integer getNodeDeptId() {
		return nodeDeptId;
	}

	public void setNodeDeptId(Integer nodeDeptId) {
		this.nodeDeptId = nodeDeptId;
	}

	public String getParentName() {
		return parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

	public String getNodeDeptName() {
		return nodeDeptName;
	}

	public void setNodeDeptName(String nodeDeptName) {
		this.nodeDeptName = nodeDeptName;
	}

	public Integer getLevels() {
		return levels;
	}

	public void setLevels(Integer levels) {
		this.levels = levels;
	}

	public Integer getForService() {
		return forService;
	}

	public void setForService(Integer forService) {
		this.forService = forService;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public List<Department> getChildren() {
		return children;
	}

	public void setChildren(List<Department> children) {
		this.children = children;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((parentId == null) ? 0 : parentId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Department other = (Department) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (parentId == null) {
			if (other.parentId != null)
				return false;
		} else if (!parentId.equals(other.parentId))
			return false;
		return true;
	}

	@Override
	public int compareTo(Department o) {
		if (this.getSorts() != null && o.getSorts() != null) {
			return this.getSorts().compareTo(o.getSorts());
		}
		return -1;
	}

}